#ifndef ZMATH_TOOLS_H_
#define ZMATH_TOOLS_H_

#include "../Common/GlobalDefines.h"
#include <algorithm>
#include <vector>

GLOBAL_NAMESPACE_BEGIN

class MathTools
{
public:
    static const double eps_double;// = 10e-10;

    template <typename T>
    static bool isZero(T data)
    {
        return std::abs(data) < eps_double;
    }

    template <typename T>
    static std::vector<T> normalize(const std::vector<T>& in)
    {
        std::vector<T> ret(in.size(), 0);
        //std::pair<std::vector<T>::const_iterator, std::vector<T>::const_iterator> minmax = std::minmax_element(in.begin(), in.end());
        T maxT = *max_element(in.begin(), in.end());
        T minT = *min_element(in.begin(), in.end());
        if (isZero(maxT - minT))
            return ret;

        for (size_t i = 0; i < in.size(); i++)
        {
            ret[i] = (in[i] - minT) / (maxT- minT);
        }
        return ret;
    }

    // operator< should be defined
    template <typename T>
    static T min(const T& a, const T& b)
    {
        return a<b ? a : b;
    }

    // operator< should be defined
    template <typename T>
    static T max(const T& a, const T& b)
    {
        return a<b ? b : a;
    }
};



GLOBAL_NAMESPACE_END

#endif//ZMATH_TOOLS_H_